/**
 * @Time    : 2022/03/09 15:19
 * @Author  : WanRongJia
 * @License : Software business license
 * @Site    : www.linshensjl.top
 * @File    : searchUser.js
 * @Software: Rich Web Platform
 * @Function: 注册用户
 * @Version : 1.0
 **/
const { matchedData } = require('express-validator')
const { buildResponse } = require('../../utils/buildResponse')
const { findUserByName } = require("../auth/helpers/findUserByName");
const { buildTransport } = require("../auth/helpers/buildTransport");
const sendMailToUser = async function (req, res) {
    try {
        req = matchedData(req)
        console.log(req)
        let transporter = await buildTransport()
        let html = ``
        let options = {
            from: '1050195858@qq.com', //发送方
            to: req.email,//接收方
            subject: req.subject,//邮件主题
            text: req.text,//邮件正文
            html: req.html || html,//html模板
            //附件信息
            /*attachments:[
                  {filename:'',path:'',}
            ]*/
        }
        transporter.sendMail(options, (err, info) => {
            if (err) {
                res.send(err)
            } else {
                res.json(buildResponse(options, '发送成功', true))
            }
        })
    } catch (e) {
        res.json(e)
    }
}

module.exports = { sendMailToUser }